//
//  AboutAPPViewController.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/15.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "AboutAPPViewController.h"

@interface AboutAPPViewController ()
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * headerView;
@property (nonatomic, strong)UILabel * peopleNumLab;//人数
@property (nonatomic, strong)UIView * bottomView;//下部框

@property (nonatomic, strong)UILabel * whatHelpTitleLab;//什么是互助
@property (nonatomic, strong)UILabel * whatHelpLab;
@property (nonatomic, strong)UIView * whatHelpTitleLine;
@property (nonatomic, strong)UIView * whatHelpContentLine;
@property (nonatomic, strong)NSString * whatHelpStr;

@property (nonatomic, strong)UILabel * whyAddTitleLab;//为什么加入
@property (nonatomic, strong)UILabel * whyAddLab;//
@property (nonatomic, strong)UIView * whyAddTitleLine;//
@property (nonatomic, strong)UIView * whyAddContentLine;//
@property (nonatomic, strong)NSString * whyAddStr;

@property (nonatomic, strong)UILabel * howRightTitleLab;//怎么保持权利
@property (nonatomic, strong)UILabel * howRightLab;//
@property (nonatomic, strong)UIView * howRightTitleLine;//
@property (nonatomic, strong)UIView * howRightContentLine;//
@property (nonatomic, strong)NSString * howRightStr;

@property (nonatomic, strong)UILabel * historyTitleLab;//过往
@property (nonatomic, strong)UILabel * historyLab;//
@property (nonatomic, strong)UIView * historyTitleLine;//
@property (nonatomic, strong)NSString * historyStr;

@property (nonatomic, strong)UIImageView * topImg;//顶部人物图片

@property (nonatomic, strong)UIButton * phoneBtn;
@property (nonatomic, strong)UIButton * normalQuestionBtn;
@property (nonatomic, strong)UIView * verticalLine;

@end

@implementation AboutAPPViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"关于博帮互助";
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view addSubview:self.tableView];
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - BOTTOM_HEIGHT - NAVI_HEIGHT) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = 42/WIDTH_6_SCALE;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.tableHeaderView = self.headerView;
        _tableView.rowHeight = 42/WIDTH_6_SCALE;
    }return _tableView;
}
- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] init];
        _headerView.backgroundColor = [UIColor whiteColor];
        //添加控件
        [self setUpHeaderViews];
    }return _headerView;
}
//tableViewHeader
- (void)setUpHeaderViews{
    //背景
    UIImageView * bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 210/WIDTH_6_SCALE)];
    bgImg.image = [UIImage imageNamed:@"bg"];
    [_headerView addSubview:bgImg];
    //图片
    UIImageView * topImg = [[UIImageView alloc] initWithFrame:CGRectMake(15/WIDTH_6_SCALE, 73/WIDTH_6_SCALE, SCREEN_WIDTH - 30/WIDTH_6_SCALE, 166/WIDTH_6_SCALE/WIDTH_6_SCALE)];
    topImg.image = [UIImage imageNamed:@"about_bg"];
    self.topImg = topImg;
    [_headerView addSubview:topImg];
    //博帮互助
    UILabel * bobangTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0/WIDTH_6_SCALE, 37/WIDTH_6_SCALE, 246/WIDTH_6_SCALE, 15/WIDTH_6_SCALE)];
    [self label:bobangTitleLab withFont:DEF_FontSize_14 withText:@"博帮互助" withTextColor:getColor(greenBGColor) withTextAlignment:NSTextAlignmentCenter withView:topImg withBGColor:[UIColor clearColor]];
    //共御风险，守护健康
    UILabel * subtitleLab = [[UILabel alloc] initWithFrame:CGRectMake(bobangTitleLab.left, 12/WIDTH_6_SCALE + bobangTitleLab.bottom, bobangTitleLab.width, bobangTitleLab.height)];
    [self label:subtitleLab withFont:DEF_FontSize_14 withText:@"共御风险，守护健康" withTextColor:getColor(greenBGColor) withTextAlignment:NSTextAlignmentCenter withView:topImg withBGColor:[UIColor clearColor]];
    //234345435643人的信赖之选
    self.peopleNumLab = [[UILabel alloc] initWithFrame:CGRectMake(bobangTitleLab.left, 12/WIDTH_6_SCALE + subtitleLab.bottom, bobangTitleLab.width, bobangTitleLab.height)];
    [self label:self.peopleNumLab withFont:DEF_FontSize_12 withText:@"45435643人的信赖之选" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentCenter withView:topImg withBGColor:[UIColor clearColor]];
    //下部框
    UIView * bottomView = [[UIView alloc] initWithFrame:CGRectMake(15/WIDTH_6_SCALE, topImg.bottom + 5/WIDTH_6_SCALE, SCREEN_WIDTH - 30/WIDTH_6_SCALE, 300/WIDTH_6_SCALE)];
    bottomView.backgroundColor = [UIColor whiteColor];
    bottomView.layer.cornerRadius = 6;
    bottomView.layer.shadowOffset = CGSizeMake(0,0);
    bottomView.layer.shadowOpacity = 0.6f;
    bottomView.layer.shadowColor = [UIColor blackColor].CGColor;
    self.bottomView = bottomView;
    [_headerView addSubview:bottomView];
    //绿色背景
    UIView * greenBGView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, bottomView.width, 35/WIDTH_6_SCALE)];
    greenBGView.backgroundColor = getColor(greenBGColor);
    [bottomView addSubview:greenBGView];
    //得到view的遮罩路径
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:greenBGView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(6,6)];
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = greenBGView.bounds;
    //赋值
    maskLayer.path = maskPath.CGPath;
    greenBGView.layer.mask = maskLayer;
    //标语
    UILabel * sloganLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, greenBGView.width, greenBGView.height)];
    [self label:sloganLab withFont:DEF_FontSize_13 withText:@"平时助一人·难时亿人助" withTextColor:[UIColor whiteColor] withTextAlignment:NSTextAlignmentCenter withView:greenBGView withBGColor:[UIColor clearColor]];
    //底部白框
    [self setUpBottomViews];
}
//底部白框
- (void)setUpBottomViews{
    //什么是互助
    UILabel * whatHelpTitleLab = [[UILabel alloc] init];
    [self label:whatHelpTitleLab withFont:DEF_FontSize_13 withText:@"什么是互助?" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:self.bottomView withBGColor:[UIColor clearColor]];
    UIView * whatHelpTitleLine = [[UIView alloc] init];
    whatHelpTitleLine.backgroundColor = getColor(@"eeeeee");
    [self.bottomView addSubview:whatHelpTitleLine];
    //什么是互助内容
    self.whatHelpLab = [[UILabel alloc] init];
    NSString * whatHelpLabStr = @"互助不是保险，互助是一人生病，众人均摊，健康时每人预存少量费用，众人积少成多，患病后，用户可从中获得一定金额的治疗费用，平时助一人，难时亿人助。";
    [self label:self.whatHelpLab withFont:DEF_FontSize_13 withText:whatHelpLabStr withTextColor:getColor(@"9b9b9b") withTextAlignment:NSTextAlignmentLeft withView:self.bottomView withBGColor:[UIColor clearColor]];
    self.whatHelpLab.lineBreakMode = 0;
    self.whatHelpLab.numberOfLines = 0;
    UIView * whatHelpContentLine = [[UIView alloc] init];
    whatHelpContentLine.backgroundColor = getColor(@"eeeeee");
    [self.bottomView addSubview:whatHelpContentLine];
    //为什么加入博帮
    UILabel *whyAddTitleLab = [[UILabel alloc] init];
    [self label:whyAddTitleLab withFont:DEF_FontSize_13 withText:@"为什么加入博帮互助?" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:self.bottomView withBGColor:[UIColor clearColor]];
    UIView * whyAddTitleLine = [[UIView alloc] init];
    whyAddTitleLine.backgroundColor = getColor(@"eeeeee");
    [self.bottomView addSubview:whyAddTitleLine];
    //为什么加入博帮内容
    self.whyAddLab = [[UILabel alloc] init];
    NSString * whyAddLabStr = @"1.已有数千万会员加入，最低均摊至没人5分钱;\n2.工艺基金会专业监督，互助金透明;\n3.信息实时公布，互助时间时刻接收监督。";
    [self label:self.whyAddLab withFont:DEF_FontSize_13 withText:whyAddLabStr withTextColor:getColor(@"9b9b9b") withTextAlignment:NSTextAlignmentLeft withView:self.bottomView withBGColor:[UIColor clearColor]];
    self.whyAddLab.lineBreakMode = 0;
    self.whyAddLab.numberOfLines = 0;
    UIView * whyAddContentLine = [[UIView alloc] init];
    whyAddContentLine.backgroundColor = getColor(@"eeeeee");
    [self.bottomView addSubview:whyAddContentLine];
    //怎样履行互助义务，保持互助权利
    UILabel *howRightTitleLab = [[UILabel alloc] init];
    [self label:howRightTitleLab withFont:DEF_FontSize_13 withText:@"怎样履行互助义务，保持互助权利?" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:self.bottomView withBGColor:[UIColor clearColor]];
    self.howRightTitleLab = howRightTitleLab;
    UIView * howRightTitleLine = [[UIView alloc] init];
    howRightTitleLine.backgroundColor = getColor(@"eeeeee");
    [self.bottomView addSubview:howRightTitleLine];
    //怎样履行互助义务，保持互助权利内容
    self.howRightLab = [[UILabel alloc] init];
    NSString * howRightLabStr = @"每次帮助遭遇大病困境的会员，您的账户都会产生扣费，为他人均摊互助金即履行互助义务；随时保持账户余额充足状态，就能保持互助权利。";
    [self label:self.howRightLab withFont:DEF_FontSize_13 withText:howRightLabStr withTextColor:getColor(@"9b9b9b") withTextAlignment:NSTextAlignmentLeft withView:self.bottomView withBGColor:[UIColor clearColor]];
    self.howRightLab.lineBreakMode = 0;
    self.howRightLab.numberOfLines = 0;
    UIView * howRightContentLine = [[UIView alloc] init];
    howRightContentLine.backgroundColor = getColor(@"eeeeee");
    [self.bottomView addSubview:howRightContentLine];
    //博帮互助帮助哪些大病会员获得互助金？
    UILabel *historyTitleLab = [[UILabel alloc] init];
    [self label:historyTitleLab withFont:DEF_FontSize_13 withText:@"怎样履行互助义务，保持互助权利?" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:self.bottomView withBGColor:[UIColor clearColor]];
    UIView * historyTitleLine = [[UIView alloc] init];
    historyTitleLine.backgroundColor = getColor(@"eeeeee");
    [self.bottomView addSubview:historyTitleLine];
    //博帮互助帮助哪些大病会员获得互助金内容
    self.historyLab = [[UILabel alloc] init];
    NSString * historyLabStr = @"截止至今日，博帮互助已经帮助568个大病会员，获得共12577万元互助金。";
    [self label:self.historyLab withFont:DEF_FontSize_13 withText:historyLabStr withTextColor:getColor(@"9b9b9b") withTextAlignment:NSTextAlignmentLeft withView:self.bottomView withBGColor:[UIColor clearColor]];
    self.historyLab.lineBreakMode = 0;
    self.historyLab.numberOfLines = 0;
    //电话咨询
    UIButton * phoneBtn = [[UIButton alloc] init];
    [phoneBtn setTitle:@"电话咨询" forState:UIControlStateNormal];
    phoneBtn.titleLabel.font = DEF_FontSize_13;
    [phoneBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_headerView addSubview:phoneBtn];
    //常见问题
    UIButton * normalQuestionBtn = [[UIButton alloc] init];
    [normalQuestionBtn setTitle:@"常见问题" forState:UIControlStateNormal];
    normalQuestionBtn.titleLabel.font = DEF_FontSize_13;
    [normalQuestionBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_headerView addSubview:normalQuestionBtn];
    //分割线
    UIView * verticalLine = [[UIView alloc] init];
    verticalLine.backgroundColor = [UIColor blackColor];
    verticalLine.centerX = SCREEN_WIDTH/2;
    [_headerView addSubview:verticalLine];
    
    self.whatHelpTitleLab = whatHelpTitleLab;
    self.whatHelpTitleLine = whatHelpTitleLine;
    self.whatHelpContentLine = whatHelpContentLine;
    self.whatHelpStr = whatHelpLabStr;
    
    self.whyAddTitleLab = whyAddTitleLab;
    self.whyAddTitleLine = whyAddTitleLine;
    self.whyAddContentLine = whyAddContentLine;
    self.whyAddStr = whyAddLabStr;
    
    self.howRightTitleLab = howRightTitleLab;
    self.howRightTitleLine = howRightTitleLine;
    self.howRightContentLine = howRightContentLine;
    self.howRightStr = howRightLabStr;

    self.historyTitleLab = historyTitleLab;
    self.historyTitleLine = historyTitleLine;
    self.historyStr = historyLabStr;

    self.phoneBtn = phoneBtn;
    self.normalQuestionBtn = normalQuestionBtn;
    self.verticalLine = verticalLine;
    
    [self setUpViewsFrame];//控件大小
}
- (void)setUpViewsFrame{
    //frame
    self.whatHelpTitleLab.frame = CGRectMake(10/WIDTH_6_SCALE, 35/WIDTH_6_SCALE, self.bottomView.width - 20/WIDTH_6_SCALE, 40/WIDTH_6_SCALE);
    self.whatHelpTitleLine.frame = CGRectMake(10/WIDTH_6_SCALE, self.whatHelpTitleLab.bottom, self.bottomView.width - 10/WIDTH_6_SCALE, 1/WIDTH_6_SCALE);
    self.whatHelpLab.frame = CGRectMake(self.whatHelpTitleLab.left, 15/WIDTH_6_SCALE + self.whatHelpTitleLine.bottom, SCREEN_WIDTH - 50/WIDTH_6_SCALE, [[self class] contentLabelHeight:self.whatHelpStr]);
    self.whatHelpContentLine.frame = CGRectMake(0, self.whatHelpLab.bottom + 15/WIDTH_6_SCALE, self.bottomView.width, 1/WIDTH_6_SCALE);
    
    self.whyAddTitleLab.frame = CGRectMake(self.whatHelpTitleLab.left, self.whatHelpContentLine.bottom, self.whatHelpTitleLab.width, self.whatHelpTitleLab.height);
    self.whyAddTitleLine.frame = CGRectMake(10/WIDTH_6_SCALE, self.whyAddTitleLab.bottom, self.bottomView.width - 10/WIDTH_6_SCALE, 1/WIDTH_6_SCALE);
    self.whyAddLab.frame = CGRectMake(self.whyAddTitleLab.left, 15/WIDTH_6_SCALE + self.whyAddTitleLab.bottom, SCREEN_WIDTH - 50/WIDTH_6_SCALE, [[self class] contentLabelHeight:self.whyAddStr]);
    self.whyAddContentLine.frame = CGRectMake(0, self.whyAddLab.bottom + 15/WIDTH_6_SCALE, self.bottomView.width, 1/WIDTH_6_SCALE);
    
    self.howRightTitleLab.frame = CGRectMake(self.whatHelpTitleLab.left, self.whyAddContentLine.bottom, self.whyAddTitleLab.width, self.whyAddTitleLab.height);
    self.howRightTitleLine.frame = CGRectMake(10/WIDTH_6_SCALE, self.howRightTitleLab.bottom, self.bottomView.width - 10/WIDTH_6_SCALE, 1/WIDTH_6_SCALE);
    self.howRightLab.frame = CGRectMake(self.howRightTitleLab.left, 15/WIDTH_6_SCALE + self.howRightTitleLab.bottom, SCREEN_WIDTH - 50/WIDTH_6_SCALE, [[self class] contentLabelHeight:self.howRightStr]);
    self.howRightContentLine.frame = CGRectMake(0, self.howRightLab.bottom + 15/WIDTH_6_SCALE, self.bottomView.width, 1/WIDTH_6_SCALE);
    
    self.historyTitleLab.frame = CGRectMake(self.whatHelpTitleLab.left, self.howRightContentLine.bottom, self.whyAddTitleLab.width, self.whyAddTitleLab.height);
    self.historyTitleLine.frame = CGRectMake(10/WIDTH_6_SCALE, self.historyTitleLab.bottom, self.bottomView.width - 10/WIDTH_6_SCALE, 1/WIDTH_6_SCALE);
    self.historyLab.frame = CGRectMake(self.howRightTitleLab.left, 15/WIDTH_6_SCALE + self.historyTitleLine.bottom, SCREEN_WIDTH - 50/WIDTH_6_SCALE, [[self class] contentLabelHeight:self.historyStr]);
    
    self.bottomView.frame = CGRectMake(15/WIDTH_6_SCALE, self.topImg.bottom + 5/WIDTH_6_SCALE, SCREEN_WIDTH - 30/WIDTH_6_SCALE, self.historyLab.bottom + 15/WIDTH_6_SCALE);
    
    self.phoneBtn.frame = CGRectMake(SCREEN_WIDTH/2 - 115/WIDTH_6_SCALE, self.bottomView.bottom, 115/WIDTH_6_SCALE, 55/WIDTH_6_SCALE);
    self.normalQuestionBtn.frame = CGRectMake(SCREEN_WIDTH/2, self.phoneBtn.top, self.phoneBtn.width, self.phoneBtn.height);
    self.verticalLine.frame = CGRectMake(SCREEN_WIDTH/2, 21/WIDTH_6_SCALE + self.bottomView.bottom, 1/WIDTH_6_SCALE, 13/WIDTH_6_SCALE);
    
    _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.normalQuestionBtn.bottom);
}

//label高度
+ (CGFloat)contentLabelHeight:(NSString *) text{
    CGRect rectToFit = [text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 50/WIDTH_6_SCALE, MAXFLOAT)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0f]}
                                          context:nil];
    return rectToFit.size.height;
}
@end
